package com.pb.metadata.controller;

import com.pb.infra.oth.entity.common.Page;
import com.pb.infra.oth.entity.common.Result;
import com.pb.infra.oth.util.Constant;
import com.pb.infra.oth.util.SysLog;
import com.pb.metadata.service.FilterTreeManService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 过滤树管理
 *
 * @Author:liudebao
 * @Date: 2021/05/01
 */
@Slf4j
@RestController
@RequestMapping("/param/filterTree")
public class FilterTreeManController {
    /**
     * 业务逻辑对象
     */
    @Autowired
    private FilterTreeManService filterTreeManService;

    private static final String TABLE_NAME = "ma_tree_filter_def";

    /**
     * 查询
     *
     * @param map 请求参数
     * @return PageResult 用户信息
     */
    @GetMapping(value = "select")
    public Result select(@RequestParam Map<String, Object> map, Page page, HttpServletRequest request) {
        return filterTreeManService.select(map, page, request);
    }

    @PostMapping(value = "selectTree")
    public Result selectTree(@RequestBody Map<String, Object> map, HttpServletRequest request) {
        return filterTreeManService.selectTree(map, request);
    }

    @PostMapping(value = "selectMetaTree")
    public Result selectMetaTree(@RequestBody  Map<String, Object> param) {
        return filterTreeManService.selectMetaTree(param);
    }

    /**
     * 保存参数应用管理信息
     *
     * @param paramMap 请求参数
     * @param request 请求
     * @return Map<String, Object> 操作返回结果
     */
    @PostMapping(value = "insertFilterTree")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.ADD)
    public Result insertFilterTree(@RequestBody Map<String, Object> paramMap, HttpServletRequest request) {
        filterTreeManService.insertFilterTree(paramMap, request);
        return Result.OK_EMPTY;
    }

    /**
     * 修改参数应用管理信息
     *
     * @param paramMap 请求参数
     * @return Map<String, Object> 操作返回结果
     */
    @PostMapping(value = "update")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.MOD)
    public Result update(@RequestBody Map<String, Object> paramMap) {
        filterTreeManService.update(paramMap);
        return Result.OK_EMPTY;
    }

    @PostMapping(value = "updateName")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.MOD)
    public Result updateName(@RequestBody Map<String, Object> paramMap) {
        filterTreeManService.updateName(paramMap);
        return Result.OK_EMPTY;
    }

    /**
     * 删除参数应用管理信息
     *
     * @param paramMap 请求参数
     * @return Map<String, Object> 操作返回结果
     */
    @PostMapping(value = "delete")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.DEL)
    public Result delete(@RequestBody List<String> paramMap) {
        filterTreeManService.delete(paramMap);
        return Result.OK_EMPTY;
    }

    /**
     * 根据法人查询维度信息
     * @param param 参数信息
     * @return Result
     */
    @PostMapping(value = "selMetaDim")
    public Result selMetaDim(@RequestBody Map<String, Object> param) {
        return filterTreeManService.selDimType(param);
    }

    /*@PostMapping(value = "selRuleFilter")
    public Result selRuleFilter(@RequestBody Map<String, Object> paramMap) {
        return filterTreeManService.selRuleFilter(paramMap);
    }*/
}
